import {create} from 'zustand'
import {GraphData, PredictiveIndicators} from "../types";

interface AppState {
    // Data
    testData: string;
    graphData:GraphData;//存储节点和边数据
    triggerType:'node' | 'edge' | 'selectRange' | 'undoRange' | '';
    triggerId:string;
    similarTableData:[];
    tensileStrength:PredictiveIndicators,
    yieldStrength:PredictiveIndicators,
    spinning:boolean,
    // Actions
    setTestData: (data: string) => void;
    setGraphData: (data: GraphData) => void;
    setTriggerType: (type: string) => void;
    setTriggerId: (id: string) => void;
    setSimilarTableData: (data:[]) => void;
    setTensileStrength:(data:PredictiveIndicators)=>void;
    setYieldStrength:(data:PredictiveIndicators)=>void;
    setSpinning:(spinning:boolean)=>void;
    //获取最新的store
    getState: () => AppState;
}

const useAppState = create<AppState>((set, get) => ({
    testData: '',
    triggerType: '',
    triggerId:'',
    similarTableData:[],
    tensileStrength:{R2:'',EVS:'',sMAPE:''},
    yieldStrength:{R2:'',EVS:'',sMAPE:''},
    spinning:true,
    //初始数据
    graphData: {
        nodes: [],
        edges: []
    },
    setTestData: (data) => set({testData: data}),
    setGraphData: (data) => set({graphData: data}),
    setTriggerType: (type) => set({triggerType: type}),
    setTriggerId: (id) => set({triggerId: id}),
    setSimilarTableData: (data) => set({similarTableData: data}),
    setTensileStrength:(data:PredictiveIndicators)=>set({tensileStrength: data}),
    setYieldStrength:(data:PredictiveIndicators)=>set({yieldStrength: data}),
    setSpinning:(spinning:boolean)=>set({spinning: spinning}),
    //获取最新的store数据并返回
    getState:()=>get()
}))

export default useAppState;

